package expriment3_bag;
import javax.swing.*;
import java.awt.*;
public class eight  extends JPanel{
    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);

        int a1[][] = new int[3][];
        int a2[][] = new int[3][];
        int i, j, k = 0;
        int a3[][] = {
                { 0, 1, 2 },
                { 3, 4, 5 },
                { 6, 7, 8 }
        };

        for (i = 0; i < 3; i++)
            a1[i] = new int[3 - i];// 创建a1[i]数组为3、2、1个元素
        for (i = 0; i < 3; i++)
            for (j = 0; j < a1[i].length; j++, k += 2)
                a1[i][j] = k;

        k = 0; // 重置 k 的值
        for (i = 0; i < 3; i++)
            a2[i] = new int[i + 3];// 创建a2[i]数组为3、4、5个元素
        for (i = 0; i < 3; i++)
            for (j = 0; j < a2[i].length; j++, k += 2)
                a2[i][j] = k;

        g.drawString("a1数组:", 20, 20);
        for (i = 0; i < 3; i++)
            for (j = 0; j < a1[i].length; j++)
                g.drawString(" " + a1[i][j], 20 + 20 * j, 40 + 20 * i);

        g.drawString("a2数组:", 115, 20);
        for (i = 0; i < 3; i++)
            for (j = 0; j < a2[i].length; j++)
                g.drawString(" " + a2[i][j], 115 + 20 * j, 40 + 20 * i);

        g.drawString("a3数组:", 230, 20);
        for (i = 0; i < 3; i++)
            for (j = 0; j < 3; j++)
                g.drawString(" " + a3[i][j], 230 + 20 * j, 40 + 20 * i);
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("数组显示");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.add(new eight());
        frame.setSize(400, 200);
        frame.setVisible(true);
    }
}
